How to use the array[key] method In Javascript
Accessing JSON array values within the JSON array elements using specific corresponding keys.
Example: Accessing value using keys of the arrays.
Javascript
let jsonArrayData = [ { "ComapnyName" : "w3wiki" , "Location" : "Noida" }, { "topics" : [ "DSA self paced course" , "Machine learning" , "Web development" , "Block Chain" , "Artificial Intelligence" ] } ]; console.log(jsonArrayData[0][ "ComapnyName" ]); console.log(jsonArrayData[1][ "topics" ]); |
Output
w3wiki [ 'DSA self paced course', 'Machine learning', 'Web development', 'Block Chain', 'Artificial Intelligence' ]
How to Get a Value from a JSON Array in JavaScript ?
We are going to iterate or access the value of a JSON array in JavaScript. There are several ways and techniques to access values from the JSON Array which are explained in detail below and are further divided into several possible techniques.
Table of Content
- Using the array[index] method
- Using the array[key] method
- Using the array.slice method
- Using for…of the loop
- Using forEach()
- Using the map() method
- Using filter() method
- Using the find() method
- Using findIndex() method
- Using some() method
- Using recursive traversal of JSON array
- Using the custom reduce method
- Using custom classes